package com.example.service;

import com.example.entity.HotBooks;
import com.example.entity.Model;
import com.example.mapper.HotBooksMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
热门书籍业务处理
 */
@Service
public class HotBooksService {

    @Resource
    private HotBooksMapper hotBooksMapper;

    public void add(HotBooks hotBooks) {
        hotBooksMapper.insert(hotBooks);
    }

    public void deleteById(Integer id) {
        hotBooksMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(HotBooks hotBooks) {
        hotBooksMapper.updateById(hotBooks);
    }

    public HotBooks selectById(Integer id) {
        return hotBooksMapper.selectById(id);
    }

    public List<HotBooks> selectAll(HotBooks hotBooks) {
        return hotBooksMapper.selectAll(hotBooks);
    }

    public PageInfo<HotBooks> selectPage(HotBooks hotBooks, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<HotBooks> hotBooksList = hotBooksMapper.selectAll(hotBooks);
        return PageInfo.of(hotBooksList);
    }
}
